<template>
  <view :class="{'image-preview-container': true, 'landscape': isLandscape}" @click="closePreview">
    <img :src="url" alt="预览图片" />
    <view v-if="isContent" class="preview-text">
      {{ content }}
    </view>
  </view>
</template>

<script>
export default {
  props: {
    url: {
      type: String,
      required: true
    },
    content: {
      type: String,
      required: true
    },
    isContent: {
      type: Boolean
    }
  },
  data() {
    return {
      showText: true,
      isLandscape: false
    };
  },
  methods: {
    closePreview() {
      this.$emit('toClose', false)
    }
  },
};
</script>

<style scoped>
.image-preview-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  cursor: pointer;
}

.landscape {
  flex-direction: row;
  align-items: flex-start;
}

.image-preview-container img {
  max-width: 100%;
  max-height: 90%;
}

.preview-text {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  padding: 10px;
  color: white;
  font-size: 18px;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.7);
}
</style>
